package com.yz.group1.group_1.controller;

import com.yz.group1.group_1.entity.AdminSchedule;
import com.yz.group1.group_1.service.AdminScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/schedule")
public class AdminScheduleController {
    @Autowired
    private AdminScheduleService adminscheduleService;

    // 合并无参和带参数查询：同一个路径，通过参数动态筛选
    @GetMapping
    public List<AdminSchedule> departmentsList(
            // 参数允许为null（required = false），未传递时不筛选
            @RequestParam(required = false) Long deptId,
            @RequestParam(required = false) Long doctorId) {
        // 调用Service层的筛选方法（需确保Service实现了该逻辑）
        return adminscheduleService.listByDeptAndDoctor(deptId, doctorId);
    }

    @PostMapping("/save")
    public boolean saveSchedule(@RequestBody AdminSchedule schedule) {
        return adminscheduleService.save(schedule);
    }

    @PutMapping("/update")
    public boolean updateSchedule(@RequestBody AdminSchedule schedule) {
        return adminscheduleService.updateById(schedule);
    }

    @DeleteMapping("/remove/{id}")
    public boolean deleteSchedule(@PathVariable Long id) {
        return adminscheduleService.removeById(id);
    }
}
